//
//  UITextField-Extension.swift
//  UITextField自定义leftView
//
//  Created by 李煜 on 2023/3/15.
//https://gamin.blog.csdn.net/article/details/118379368?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-118379368-blog-126262325.pc_relevant_multi_platform_whitelistv3&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-118379368-blog-126262325.pc_relevant_multi_platform_whitelistv3&utm_relevant_index=1

import UIKit

extension UITextField {

  /// 添加左内边距
  public func addLeftTextPadding(_ blankSize: CGFloat) {
    let leftView = UIView()
    leftView.frame = CGRect(x: 0, y: 0, width: blankSize, height: frame.height)
    self.leftView = leftView
    self.leftViewMode = UITextField.ViewMode.always
  }

  /// 在文本框的左边添加一个图标
  public func addLeftIcon(_ image: UIImage?, frame: CGRect, imageSize: CGSize) {
    let leftView = UIView()
    leftView.frame = frame
    let imgView = UIImageView()
    imgView.frame = CGRect(x: (frame.width - imageSize.width) / 2, y: (frame.height - imageSize.height) / 2, width: imageSize.width, height: imageSize.height)
    imgView.image = image
    leftView.addSubview(imgView)
    self.leftView = leftView
    self.leftViewMode = UITextField.ViewMode.always
  }

}
